<!-- eslint-disable vue/multi-word-component-names -->

<template>
    <teleport to="#back">
        <div
    class="d-flex justify-content-center align-items-center h-100 w-100 loading-container"
  >
    <div class="loading-content">
      <div class="spinner-border text-primary" role="status">
        <span class="visually-hidden">{{text ||'Loading'}}</span>
      </div>
      <p class="text-primary small">{{text}}</p>
    </div>
  </div>
    </teleport>
  
</template>

<script lang="ts">
import { defineComponent, onUnmounted } from "vue";

export default defineComponent({
    props:{
        text:{
            type:String
        }
    },
  setup() {
    // 创建需要的节点
    const node = document.createElement('div')
    node.id = 'back'
    document.body.appendChild(node)
    // 每跳一次页面就会创建一个back节点
    onUnmounted(()=>{
        // 卸载 加入的loading节点
        document.body.removeChild(node)
    })
    return {};
  },
});
</script>

<style>
.loading-container {
background: rgba(255, 255, 255, 0.5);
z-index: 100;
position: fixed;
top: 0;
left: 0;
}
.loading-content {
text-align: center;
}
</style>
